package com.service;

import com.Dao.UserDao;
import com.bean.User;

import java.sql.SQLException;

public class UserService {
    private UserDao dao=new UserDao();

    //注册用户
    public void register(User user) {
        try{
            dao.adduser(user);
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("注册失败！！！");
        }
    }

    //登录
    public User login(String username, String password) throws  Exception{
        User user=dao.findUserByNameandPwd(username,password);
        if(user==null){
            System.out.println("登录失败");
        }
        return user;
    }

    //修改用户信息
    public boolean update(User user){
        try {
            dao.updateUer(user);
            return true;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            return false;
        }
    }

    //查询用户
    public User findUserByNameAndPwd(String username,String password)throws SQLException {
        return dao.findUserByNameandPwd(username,password);
    }

    //查找博主信息
    public User queryBlogger() throws SQLException {
        return dao.queryBlogger();
    }
}
